import os

from ddt import ddt, unpack, data

from BasicAPI.basic_API import BasicAPI
from src import TestCaseMore
from src import Config as config
from src import Public as pb


@ddt
class TestLogin(TestCaseMore, BasicAPI):
	describe = ""
	data_path = os.path.join(config.project_dir, "Data", "test_login.xlsx")
	datas = pb.get_data_from_excel(file_path=data_path, sheet_name="login")

	def test_01_login(self):
		"""
		单条用例:11111111111111
		:return:
		"""
		# 读文件获取测试数据
		kwargs = pb.get_data_from_excel(file_path=self.data_path, sheet_name="login", idx=2)
		self.describe = kwargs.get("describe")

		# 发请求
		response = self.login(**kwargs)

		# 断言
		expected = eval(kwargs.get("expected"))
		self.assertEqual(response.get("msg"), expected.get("msg"),
						 f"登录接口响应与预期不一致，预期：{expected.get('msg')}，响应：{response.get('msg')}", "error")

	@data(*datas)
	def test_ll(self, data2):
		self.describe = data2.get("title") + data2.get("describe")
		# 发请求
		response = self.login(**data2)

		# 断言
		expected = eval(data2.get("expected"))
		self.assertEqual(response.get("msg"), expected.get("msg"),
						 f"登录接口响应与预期不一致，预期：{expected.get('msg')}，响应：{response.get('msg')}", "error")


if __name__ == '__main__':
	pass
